# Maintainer: Kyle Keen <keenerd@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Jose Negron <josenj.arch@mailnull.net>

pkgname=sdcc
pkgver=4.2.0
pkgrel=3
pkgdesc="Retargettable ANSI C compiler (Intel 8051, Maxim 80DS390, Zilog Z80 and the Motorola 68HC08)"
arch=('loong64' 'x86_64')
license=('GPL')
depends=('bash' 'gcc-libs' 'boost-libs')
makedepends=('gputils' 'flex' 'bison' 'patch' 'boost')
optdepends=('python')
url="http://sdcc.sourceforge.net/"
options=(!strip  staticlibs)
source=(https://downloads.sourceforge.net/sourceforge/sdcc/$pkgname-src-${pkgver//_/-}.tar.bz2)
md5sums=('cc5042a207b15c387185867ca1b32145')
sha256sums=('b49bae1d23bcd6057a82c4ffe5613f9cd0cbcfd1e940e9d84c4bfe9df0a8c053')

# namcap claims boost-libs isn't needed, investigate this

prepare() {
  cd "$srcdir/$pkgname-$pkgver"
  sed -i 's|CC -E|CC -O2 -E|g' support/sdbinutils/libiberty/configure
}

build() {
  cd "$srcdir/$pkgname-$pkgver"
  ./configure \
	--prefix=/usr \
	--includedir=/usr/include/sdcc \
	--libdir=/usr/lib/sdcc \
	--disable-werror
  make
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  make install DESTDIR="$pkgdir"

  if [ -d "$pkgdir/usr/lib/lib" ]; then
    mv "$pkgdir/usr/lib/lib/"* "$pkgdir/usr/lib/sdcc/"
    rm -rf "$pkgdir/usr/lib/lib"
  fi

  sed -i 's|#!/usr/bin/env python|#!/usr/bin/env python3|' "$pkgdir/usr/bin/as2gbmap"
}
